package com.group.itms.routes.utils;

import com.group.itms.routes.R;
import com.group.itms.routes.adapters.MultiViewTypeAdapter;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Item implements ListViewItem {

	private String mValue;
	private int mIcResId;
	private Object mData;

	public Item(String value) {
		this(value, -1);
	}
	
	public Item(String value, Object data) {
		this(value, -1, data);
	}

	public Item(String value, int icResId) {
		this(value, icResId, null);
	}

	public Item(String value, int icResId, Object data) {
		mValue = value;
		mIcResId = icResId;
		mData = data;
	}

	public void setData(Object data) {
		mData = data;
	}

	@Override
	public int getViewType() {
		return MultiViewTypeAdapter.VIEW_TYPE_ITEM;
	}

	@Override
	public View getView(LayoutInflater inflater, View convertView) {
		View v = convertView != null ? convertView : inflate(inflater);
		ImageView iv = (ImageView) v.findViewById(R.id.icon);
		if (mIcResId == -1) {
			iv.setVisibility(View.GONE);
		} else {
			iv.setVisibility(View.VISIBLE);
			iv.setImageResource(mIcResId);
		}
		((TextView) v.findViewById(R.id.text)).setText(mValue);
		return v;
	}

	private View inflate(LayoutInflater inflater) {
		return inflater.inflate(R.layout.item_layout, null);
	}

	@Override
	public Object getData() {
		return mData;
	}

	@Override
	public boolean isClickable() {
		return true;
	}

}
